package com.lovo.controller;

import com.lovo.model.UserDO;
import com.lovo.model.UserDTO;
import com.lovo.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

//@Controller
//@ResponseBody
@RestController
@RequestMapping("/users")
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(){
        return "hello index";
    }


    @GetMapping
    public List findAll(String name){
        System.out.println(name);
        return userService.findAll();
    }
    @GetMapping("/{id}")
    public UserDO findById(@PathVariable("id") Integer id){
        return userService.findByID(id);
    }
    @PostMapping
    public String save(@Valid @RequestBody UserDTO userDTO){
        System.out.println(userDTO);
        return "增加";
    }

    @PutMapping("/{id}")
    public String update(@PathVariable("id") Integer id,@RequestBody UserDTO userDTO){
        System.out.println("id:"+userDTO);
        return "update "+id;
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Integer id){
        return "delete "+id;
    }


}
